package com.erp.database.base;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

public class CommonBaseController {

	@InitBinder
	protected void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		CustomDateEditor dateEditor = new CustomDateEditor(format, true);
		binder.registerCustomEditor(Date.class, dateEditor);
	}

	/**
	 * 获取request参数
	 * @param request
	 * @return
	 */
	protected Map<String,String> getParamterMap(HttpServletRequest request){
		Map<String,String>paramMap=new HashMap<String,String>();
		Enumeration<String> keys=request.getParameterNames();
		while(keys.hasMoreElements()){
			String key=keys.nextElement();
			String v=request.getParameter(key);
			paramMap.put(key, v);
		}
		return paramMap;
	}
	
}
